

cc.Class({
    extends: cc.Component,

    properties: {
       poolName:'enemyPool',
       //initCount: 5,
       enemyPrefab:{
            default: null,
            type: cc.Prefab,
       }
    },

  

    // onLoad () {},

    start () {
        this.enemyPool = new cc.NodePool();
        let initCount = 3;
       for (let i = 0; i < initCount; i++) {
          let enemy = cc.instantiate(this.enemyPrefab); //创建节点
          this.enemyPool.put(enemy); //放入对象池
          enemy.nodePool = this;
       }
    },
    //获取
    createEnemyPool:function(){
        let enemy = null;
        if (this.enemyPool.size() > 0 ) {
            enemy = this.enemyPool.get();
        }else{
            enemy = cc.instantiate(this.enemyPrefab);
        }
        return enemy;
    },
    //返回
    onEnemyKilled:function (enemy) {
        this.enemyPool.put(enemy);  
    },
    //  update (dt) {

    //  },
});
